/*
 * @lc app=leetcode.cn id=345 lang=cpp
 *
 * [345] 反转字符串中的元音字母
 */

// @lc code=start

class Solution
{
public:
  string reverseVowels(string s)
  {
    unordered_set<char> vowel = {'a', 'e', 'i', 'o', 'u',
                                 'A', 'E', 'I', 'O', 'U'};
    for (int l = 0, r = s.size() - 1; l < r; ++l, --r) {
      while (l < r && vowel.find(s[l]) == vowel.end()) ++l;
      while (l < r && vowel.find(s[r]) == vowel.end()) --r;
      char tmp = s[l];
      s[l]     = s[r];
      s[r]     = tmp;
    }
    return s;
  }
};
// @lc code=end
